//
//  ContainerViewController.m
//  News
//
//  Created by wangshan on 16/2/24.
//  Copyright © 2016年 News. All rights reserved.
//



#import "ContainerViewController.h"
#import "NewsViewController.h"
#import "VideoViewController.h"
#import "PictureViewController.h"
#import "SuperViewController.h"



@interface ContainerViewController ()<UITabBarControllerDelegate>



@end

@implementation ContainerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    
   
    self.delegate = self;
    
    
    UINavigationController *newsNC = [[UIStoryboard storyboardWithName:@"News" bundle:nil] instantiateViewControllerWithIdentifier:@"newsNC"];
    
    newsNC.tabBarItem.image = [UIImage imageNamed:@"news"];

//    VideoViewController *videoVC = [[UIStoryboard storyboardWithName:@"Video" bundle:nil]instantiateViewControllerWithIdentifier:@"VideoVC"];
//    
//    videoVC.view.tag = 3;
//    
//    videoVC.title = @"视频";
//    videoVC.tabBarItem.image = [UIImage imageNamed:@"video"];
//    
    
    UINavigationController *userNC = [[UIStoryboard storyboardWithName:@"User" bundle:nil] instantiateViewControllerWithIdentifier:@"UserNC"];
    userNC.title = @"我的";
    userNC.tabBarItem.image = [UIImage imageNamed:@"person"];
    
    PictureViewController *picVC = [[UIStoryboard storyboardWithName:@"Picture" bundle:nil] instantiateViewControllerWithIdentifier:@"PicVC" ];
    
    picVC.tabBarItem.image = [UIImage imageNamed:@"picture"];
    picVC.title = @"图片" ;
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.viewControllers = @[newsNC,picVC,userNC];


}

- (BOOL)shouldAutorotate {
    return YES;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
    
    return UIInterfaceOrientationMaskPortrait;
}
//
//-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
//    
//    return UIInterfaceOrientationMaskPortrait;
//}

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController*)viewController
{
    CATransition *animation =[CATransition animation];
    [animation setDuration:0.3f];
//    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

    
    
    [animation setType:kCATransitionFade];
    [animation setSubtype:kCATransitionFromRight];
    
    
    
    [tabBarController.view.layer addAnimation:animation forKey:@"reveal"];
    
  
    
    UIViewController *controller = tabBarController.selectedViewController;
    if ([viewController isEqual:controller]) {
        
        //执行刷新动作
        
     
        
        if ([_clikDelegeta respondsToSelector:@selector(refreshData)]) {
            
            
            [_clikDelegeta refreshData];
            
        }
        
        
        
    }
    
    
    return YES;
}


@end
